<!--  -->
<template>
  <div class="app-container">
    <!-- START 卡片视图 START -->
    <el-card style="margin-bottom: 10px;">
      <!-- START 搜索与添加按扭区域 START -->
      <el-form ref="queryForm" :model="queryParams" :inline="true">
        <el-form-item label="员工姓名" prop="empName">
          <el-input
            v-model="queryParams.empName"
            style="width: 200px"
            size="small"
            placeholder="请输入员工名进行搜索"
            clearable
            @clear="getEmployeeList"
          />
        </el-form-item>
        <el-form-item label="政治面貌" prop="politicsId">
          <el-select v-model="queryParams.politicsId" size="small" style="width: 200px" placeholder="政治面貌">
            <el-option v-for="item in politcList" :key="item.id" :value="item.id" :label="item.name" />
          </el-select>
        </el-form-item>
        <el-form-item label="所属部门" prop="deptId">
          <tree-select
            v-if="showBm"
            ref="treeRefQuery"
            :width="200"
            :data="deptList"
            :default-props="defaultProps"
            :node-key="nodeKey"
            :checked-keys="checkDeptList"
            @popoverHide="popoverHideQuery"
          />
        </el-form-item>
        <el-form-item label="入职时间" prop="politicsName">
          <el-date-picker
            v-model="beginContract"
            size="small"
            style="width: 260px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            type="primary"
            size="mini"
            @click="getEmployeeList"
          >搜索
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button
            v-hasPermi="['/employee/basic/saveBasic']"
            type="primary"
            plain
            size="mini"
            icon="el-icon-plus"
            @click="openRightDialog"
          >新增
          </el-button>
          <el-upload
            style="display: inline-flex;"
            :show-file-list="false"
            :before-upload="beforeUpload"
            :on-success="onSuccess"
            :on-error="onError"
            :disabled="importDataDisabled"
            :headers="headers"
            action="/employee/basic/importData"
          >
            <el-button
              v-hasPermi="['/employee/basic/importData']"
              type="success"
              plain
              size="mini"
              :icon="importDataBtnIcon"
            >{{ importDataBtnText }}
            </el-button>
          </el-upload>
          <el-button
            v-hasPermi="['/employee/basic/exportData']"
            type="warning"
            plain
            size="mini"
            icon="el-icon-download"
            @click="handleExport"
          >导出
          </el-button>
        </el-form-item>
      </el-form>
      <!--  END 搜索与添加按扭区域 END -->
    </el-card>
    <!-- END 卡片视图 END -->

    <!-- START员工基本资料表格区域 START -->
    <el-card>
      <el-table
        v-loading="listLoading"
        :data="empBasicList"
        fit
        border
        highlight-current-row
        style="width: 100%;"
        @sort-change="sortChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column fixed="left" label="ID" prop="id" sortable="custom" align="center" width="60" :class-name="sortEmp('id')">
          <template slot-scope="{row}">
            <span>{{ row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="left" label="姓名" width="80px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="工号" width="90px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.workID }}</span>
          </template>
        </el-table-column>
        <el-table-column label="性别" width="50px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.gender }}</span>
          </template>
        </el-table-column>
        <el-table-column label="出生日期" width="100px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.birthday }}</span>
          </template>
        </el-table-column>
        <el-table-column label="身份证号码" width="170px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.idCard }}</span>
          </template>
        </el-table-column>
        <el-table-column label="婚姻状况" width="80px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.wedlock }}</span>
          </template>
        </el-table-column>
        <el-table-column label="民族" width="70px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.nation.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="籍贯" width="100px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.nativePlace }}</span>
          </template>
        </el-table-column>
        <el-table-column label="政治面貌" width="120px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.politicsStatus.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="电子邮箱" width="180px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.email }}</span>
          </template>
        </el-table-column>
        <el-table-column label="电话号码" width="120px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.phone }}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系地址" width="340px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.address }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所属部门" width="120px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.department.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="职称" width="130px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.position.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="聘用形式" width="90px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.engageForm }}</span>
          </template>
        </el-table-column>
        <el-table-column label="最高学历" width="80px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.tiptopDegree }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所属专业" width="150px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.specialty }}</span>
          </template>
        </el-table-column>
        <el-table-column label="毕业院校" width="140px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.school }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入职日期" width="120px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.beginDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="在职状态" width="80px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.workState }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入职日期" width="100px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.beginDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="转正日期" width="100px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.conversionTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="合同起始日期" width="110px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.beginContract }}</span>
          </template>
        </el-table-column>
        <el-table-column label="合同终止日期" width="110px" align="center">
          <template slot-scope="{row}">
            <span>{{ row.endContract }}</span>
          </template>
        </el-table-column>
        <el-table-column label="合同期限" width="80px" align="center">
          <template slot-scope="{row}">
            <el-tag>{{ row.contractTerm }}</el-tag>
            年
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="210" class-name="small-padding fixed-width">
          <template slot-scope="{row,$index}">
            <el-button
              v-hasPermi="['/employee/basic/updateBasic']"
              type="primary"
              icon="el-icon-edit"
              size="mini"
              plain
              round
              @click="editEmpDialog(row)"
            >
              编辑
            </el-button>
            <el-button
              v-hasPermi="['/employee/basic/delBasic']"
              size="mini"
              icon="el-icon-delete"
              type="danger"
              plain
              round
              @click="handleDelete(row,$index)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalCount>0"
        :total="totalCount"
        :page.sync="queryParams.currPageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getEmployeeList"
      />
    </el-card>
    <!-- END 员工基本资料表格区域 END -->
    <!-- START 添加员工基本资料弹出对话框窗口 START -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="1100px">
      <el-form ref="dataFormRef" :rules="rules" :model="emp" label-position="left" style="width: 1100px;">
        <el-row>
          <el-col :span="5">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="emp.name" size="medium" style="width:170px;" placeholder="姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="性别" prop="gender">
              <el-radio-group v-model="emp.gender">
                <el-radio label="男">男</el-radio>
                <el-radio label="女">女</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="出生日期" prop="birthday">
              <el-date-picker v-model="emp.birthday" size="medium" value-format="yyyy-MM-dd" placeholder="出生日期" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="政治面貌" prop="politicId">
              <el-select v-model="emp.politicId" style="width:210px;" size="medium" placeholder="政治面貌">
                <el-option v-for="item in politcList" :key="item.id" :value="item.id" :label="item.name" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <el-form-item label="民族" prop="nationId">
              <el-select v-model="emp.nationId" size="medium" placeholder="民族" style="width:170px;">
                <el-option v-for="item in nations" :key="item.id" :value="item.id" :label="item.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="籍贯" prop="nativePlace" size="medium">
              <el-input v-model="emp.nativePlace" style="width:170px" placeholder="籍贯" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="电子邮箱" prop="email" size="medium">
              <el-input v-model="emp.email" style="width:220px" placeholder="电子邮箱" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="联系地址" prop="address">
              <el-input v-model="emp.address" style="width:210px" placeholder="联系地址" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <el-form-item label="职位" prop="posId">
              <el-select v-model="emp.posId" style="width:170px;" size="medium" placeholder="职位">
                <el-option v-for="item in positions" :key="item.id" :value="item.id" :label="item.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="职称" prop="jobLevelId">
              <el-select v-model="emp.jobLevelId" size="medium" placeholder="职称" style="width:170px;">
                <el-option v-for="item in joblevels" :key="item.id" :value="item.id" :label="item.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="所属部门" prop="departmentId">
              <tree-select
                ref="treeRef"
                :width="150"
                :data="treeDeptList"
                :default-props="defaultProps"
                :node-key="nodeKey"
                :checked-keys="defaultCheckedKeys"
                @popoverHide="popoverHide"
              />

            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="电话号码" prop="phone">
              <el-input v-model="emp.phone" style="width:200px;" placeholder="电话号码" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="5">
            <el-form-item label="工号" prop="workID">
              <el-input v-model="emp.workID" style="width:170px;" placeholder="工号" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="学历" prop="tiptopDegree">
              <el-select v-model="emp.tiptopDegree" size="medium" placeholder="学历" style="width:170px;">
                <el-option value="博士" label="博士" />
                <el-option value="硕士" label="硕士" />
                <el-option value="本科" label="本科" />
                <el-option value="大专" label="大专" />
                <el-option value="高中" label="高中" />
                <el-option value="初中" label="初中" />
                <el-option value="小学" label="小学" />
                <el-option value="其他" label="其他" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="毕业院校" prop="school">
              <el-input v-model="emp.school" placeholder="毕业院校" style="width: 220px" />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="专业名称" prop="specialty">
              <el-input v-model="emp.specialty" style="width: 210px;" placeholder="专业名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <el-form-item label="入职" prop="beginDate">
              <el-date-picker
                v-model="emp.beginDate"
                style="width: 170px;"
                value-format="yyyy-MM-dd"
                placeholder="入职日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="转正" prop="conversionTime">
              <el-date-picker
                v-model="emp.conversionTime"
                style="width: 170px;"
                value-format="yyyy-MM-dd"
                placeholder="转正日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="合同起始" prop="beginContract">
              <el-date-picker
                v-model="emp.beginContract"
                style="width: 220px;"
                value-format="yyyy-MM-dd"
                placeholder="合同起始日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="合同终止" prop="endContract">
              <el-date-picker
                v-model="emp.endContract"
                style="width:210px;"
                value-format="yyyy-MM-dd"
                placeholder="合同终止日期"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="身份证号" prop="idCard">
              <el-input v-model="emp.idCard" size="medium" style="width:240px;" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="聘用方式" prop="engageForm">
              <el-radio-group v-model="emp.engageForm" size="medium">
                <el-radio label="劳动合同">劳动合同</el-radio>
                <el-radio label="劳务合同">劳务合同</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="婚姻状况" prop="wedlock">
              <el-radio-group v-model="emp.wedlock" size="medium">
                <el-radio label="已婚">已婚</el-radio>
                <el-radio label="未婚">未婚</el-radio>
                <el-radio label="离异">离异</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelEvent()">
          取消
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?insertData():updateData()">
          确认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';

import { getEmpList, nations, saveBasic, positions, treeDeptList, joblevels, maxWorkID, updateBasic, delBasic } from '@/api/employee'
import Pagination from '@/components/Pagination'
import { getToken } from '@/utils/auth'
import TreeSelect from '@/components/TreeSelect'

export default {
// import引入的组件需要注入到对象中才能使用
  components: {
    Pagination,
    TreeSelect
  },
  // props实现父子组件传递数据
  props: {},
  data() {
    // 这里存放数据
    return {
      showBm: true,
      emp: {
        name: '',
        gender: '男',
        birthday: '',
        idCard: '',
        wedlock: '已婚',
        nationId: 1,
        nativePlace: '',
        politicId: 1,
        email: '',
        phone: '',
        address: '',
        departmentId: 1,
        jobLevelId: 1,
        posId: 1,
        engageForm: '劳动合同',
        tipTopDegree: '本科',
        specialty: '',
        school: '',
        workState: '在职',
        workID: '',
        contractTerm: '',
        conversionTime: '',
        notWorkDate: '',
        beginContract: '',
        endContract: ''
      },
      // 民族列表
      nations: [],
      // 树状部门列表
      treeDeptList: [],
      // 职称列表
      joblevels: [],
      // 职位列表
      positions: [],
      // 控制新增员工对话框的显示与隐藏
      dialogFormVisible: false,
      textMap: {
        update: '编辑员工',
        create: '新增员工'
      },
      dialogStatus: 'create',
      // 添加表单验证规则对象
      rules: {
        name: [{ required: true, message: '姓名必填', trigger: 'blur' }],
        gender: [{ required: true, message: '性别必填', trigger: 'blur' }],
        birthday: [{ required: true, message: '出生日期必填', trigger: 'blur' }],
        politicId: [{ required: true, message: '政治面貌必填', trigger: 'blur' }],
        nationId: [{ required: true, message: '民族必填', trigger: 'blur' }],
        nativePlace: [{ required: true, message: '籍贯必填', trigger: 'blur' }],
        email: [{ required: true, message: '邮箱必填', trigger: 'blur', type: 'email' }],
        address: [{ required: true, message: '联系地址必填', trigger: 'blur' }],
        posId: [{ required: true, message: '职位必填', trigger: 'blur' }],
        jobLevelId: [{ required: true, message: '职称必填', trigger: 'blur' }],
        departmentId: [{ required: true, message: '部门必填', trigger: 'blur' }],
        phone: [{ required: true, message: '电话号码必填', trigger: 'blur' }], workID: [{ required: true, message: '工号必填', trigger: 'blur' }],
        tiptopDegree: [{ required: true, message: '学历必填', trigger: 'blur' }],
        school: [{ required: true, message: '毕业院校必填', trigger: 'blur' }],
        specialty: [{ required: true, message: '专业必填', trigger: 'blur' }],
        beginDate: [{ required: true, message: '入职日期必填', trigger: 'blur' }],
        conversionTime: [{ required: true, message: '转正日期必填', trigger: 'blur' }],
        beginContract: [{ required: true, message: '合同起始日期必填', trigger: 'blur' }],
        endContract: [{ required: true, message: '合同终止日期必填', trigger: 'blur' }],
        idCard: [{ required: true, message: '身份证号必填', trigger: 'blur' }],
        engageForm: [{ required: true, message: '聘用方式必填', trigger: 'blur' }],
        wedlock: [{ required: true, message: '婚姻状况必填', trigger: 'blur' }]
      },
      // 新增员工对话框里的所属部门树状下拉框
      defaultProps: {
        children: 'children', // 树形控件的子节点
        label: 'name' // 以权限名作为树形控件的显示值
      },
      nodeKey: 'id', // 以权限编号作为当前树形控件中节点的key
      // 默认选择树形控件中根节点
      defaultCheckedKeys: [],
      checkDeptList: [],
      queryParams: {
        empName: '',
        politicsId: '',
        deptId: '',
        pageSize: 5,
        currPageNo: 1,
        beginTime: '',
        endTime: '',
        sort: '+id'
      },
      beginContract: [],
      listLoading: false,
      // 上传成功后<el-upload>标签设置为禁用的
      importDataDisabled: false,
      importDataBtnIcon: 'el-icon-upload2',
      importDataBtnText: '导入',
      politcList: [],
      deptList: [],
      empBasicList: [],
      totalCount: 0,
      headers: {
        // 调用getToken()实现从Cookie中获取token字符串
        Authorization: getToken()
      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {
    emp: function(val) { // 语法：属性名:function(){} 即可实现对某个属性的数据进行监听
      this.$nextTick(function() {
        this.$refs.treeRef.$emit('updateCheckedKey')
      })
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getEmployeeList()
    this.getNations()
    this.getTreeDeptList()
    this.getJoblevels()
    this.getPositions()
    this.getPositions()
  },
  // 方法集合
  methods: {
    sortChange({ order, prop }) {
      console.log(prop, order)
      if (order === 'ascending') {
        this.queryParams.sort = '+id'
      } else {
        this.queryParams.sort = '-id'
      }
      this.queryParams.currPageNo = 1
      this.getEmployeeList()
    },
    sortEmp(key) {
      let sort = ''
      if (this.queryParams.sort) {
        sort = this.queryParams.sort
      }
      return sort === `ascending_${key}` ? 'ascending' : 'descending'
    },
    // 查询所有的民族
    getNations() {
      nations().then(res => {
        this.nations = res
      })
    },
    // 获取带层级的部门列表
    getTreeDeptList() {
      treeDeptList().then(res => {
        this.treeDeptList = res
      })
    },
    //  查询所有的职称
    getJoblevels() {
      joblevels().then(res => {
        this.joblevels = res
      })
    },
    // 查询所有的职位
    getPositions() {
      positions().then(res => {
        this.positions = res
      })
    },
    // 得到新增员工基本资料时的工号
    getMaxWorkID() {
      maxWorkID().then(res => {
        this.emp.workID = res.data
      })
    },
    // 下拉菜单节点选中事件，checkedIds为选中节点的nodeKey值，checkedData为选中节点对象
    // checkedData.id得到菜单编号、checkedData.name得到菜单名
    popoverHide(checkedIds, checkedData) {
      console.log(checkedIds)
      console.log(checkedData)
      this.emp.departmentId = checkedData.id
    },
    popoverHideQuery(checkedIds, checkedData) {
      console.log(checkedIds)
      console.log(checkedData)
      this.checkDeptList = [checkedData.id]
      this.queryParams.deptId = checkedData.id
    },
    beforeUpload() {
      // 上传文件之前的钩子，
      this.importDataBtnIcon = 'el-icon-loading'
      this.importDataBtnText = '正在导入'
      // 上传前<el-upload>标签设置为启用的
      this.importDataDisabled = true
    },
    onSuccess() {
      this.importDataBtnIcon = 'el-icon-upload2'
      this.importDataBtnText = '导入'
      // 上传成功后<el-upload>标签设置为禁用的
      this.importDataDisabled = false
      this.getEmployeeList()
    },
    getEmployeeList() {
      if (this.beginContract) {
        this.queryParams.beginTime = this.beginContract[0]
        this.queryParams.endTime = this.beginContract[1]
      } else {
        this.queryParams.beginTime = ''
        this.queryParams.endTime = ''
      }
      this.listLoading = true
      console.log(this.queryParams)
      getEmpList(this.queryParams).then(res => {
        const { data } = res
        this.totalCount = data.pages.total
        this.empBasicList = data.pages.list
        this.queryParams.currPageNo = data.pages.pageIndex
        this.deptList = data.deptList
        this.politcList = data.politcList
        this.listLoading = false
      }).catch(err => {
        console.log(err)
      })
    },
    // 新增员工按扭的点击事件
    openRightDialog() {
      // 重置Emp对象
      this.resetEmp()
      this.getMaxWorkID()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      // 得到新增员工基本资料时的工号
    },
    resetEmp() {
      this.emp = {
        name: '',
        gender: '男',
        birthday: '',
        idCard: '',
        wedlock: '已婚',
        nationId: 1,
        nativePlace: '',
        politicId: 1,
        email: '',
        phone: '',
        address: '',
        departmentId: 1,
        jobLevelId: 1,
        posId: 1,
        engageForm: '劳动合同',
        tipTopDegree: '本科',
        specialty: '',
        school: '',
        workState: '在职',
        contractTerm: '',
        conversionTime: '',
        notWorkDate: '',
        beginContract: '',
        endContract: ''
      }
    },
    // 新增员工对话框中[确认]按扭的点击事件
    insertData() {
      this.$refs.dataFormRef.validate((valid) => {
        if (valid) {
          // 调用employee.js中的saveBasic方法发送请求到后端实现保存新增的员工信息
          saveBasic(this.emp).then((res) => {
            // false隐藏新增员工基本资料对话框
            this.dialogFormVisible = false
            if (res.code === 200) {
              // 新增员工信息成功后，再刷新员工信息列表，获取最新的员工信息
              this.getEmployeeList()
              this.$message({
                title: '提示',
                message: res.message,
                type: 'success',
                duration: 2000
              })
            } else {
              this.$message({
                title: '提示',
                message: res.message,
                type: 'error',
                duration: 2000
              })
            }
          })
        }
      })
    }, // 添加员工基本资料对话框中的取消按扭点击事件
    // 新增员工对话框中[确认]按扭的点击事件
    updateData() {
      this.$refs.dataFormRef.validate((valid) => {
        if (valid) {
          // 调用employee.js中的saveBasic方法发送请求到后端实现保存新增的员工信息
          updateBasic(this.emp).then((res) => {
            // false隐藏新增员工基本资料对话框
            this.dialogFormVisible = false
            if (res.code === 200) {
              // 新增员工信息成功后，再刷新员工信息列表，获取最新的员工信息
              this.$message({
                title: '提示',
                message: res.message,
                type: 'success',
                duration: 2000
              })
            } else {
              this.$message({
                title: '提示',
                message: res.message,
                type: 'error',
                duration: 2000
              })
            }
          })
        }
      })
    },
    cancelEvent() {
      this.dialogFormVisible = false
      // 重置表单数据
      this.$refs.dataFormRef.resetFields()
    },
    resetQuery() {
      this.showBm = false
      this.queryParams = {
        empName: '',
        politicsId: '',
        deptId: '',
        beginTime: '',
        endTime: ''
      }
      this.checkDeptList = []
      this.$nextTick(function() {
        this.showBm = true
      })
    },
    onError() {
      this.importDataBtnIcon = 'el-icon-upload2'
      this.importDataBtnText = '导入'
    },
    handleExport() {
      console.log('导出', this.queryParams)
      this.downloadRequest('/employee/basic/exportData', this.queryParams)
    },
    handleImport() {

    },
    editEmpDialog(emp) {
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.emp = emp
      this.defaultCheckedKeys = []
      this.defaultCheckedKeys.push(emp.departmentId)
    },
    handleDelete(emp, index) {
      console.log(emp)
      delBasic(emp.id).then(res => {
        if (res.code === 200) {
          this.getEmployeeList()
        }
      })
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped>
  .el-row { height: 58px;}
</style>
